var clearUserPassword = function(id) {
	Ext.Ajax.request({
		url : "review_clearPassword.do",
		params : {
			// mapping to field named 'msisdn' of
			// mobileUserSearchAction at the backend
			'user.id' : id
		},
		success : function(resp) {
			var rp = Ext.decode(resp.responseText);
			if (rp.success == true || rp.success == 'true') {
				Ext.MessageBox.alert('提示', '清除成功!');
			} else {
				Ext.MessageBox.alert('错误', '错误信息:' + rp.message);
			}
		}

	});
};

Ext.ns("crs.grid");

crs.grid.ReviewedApplicantGridPanel = Ext.extend(Ext.grid.EditorGridPanel,
		{

			/* begin of fields initialization */
			autoHeight : true,
			default_url : 'review_reviewedApplicants.do',
			search_url : 'review_userSearch.do',
			defaultProxy : '',
			searchProxy : '',
			pageSize : 15,
			closable : true,
			root : 'listUser',
			totalProperty : 'pagination.totalCount',
			title : '用户审核记录',
			viewConfig : {
				deferEmptyText : false,
				emptyText : '没有可显示数据',
				forceFit : true
			},
			fields : [ 'id', 'userName', 'companyName', 'country', 'province',
					'city', 'registerTime', 'status', 'contactNumber',
					'phoneNumber', 'email', 'contact' ],
			columns : [
					{
						header : '用户名',
						dataIndex : 'userName'
					},
					{
						header : '单位名称或姓名',
						dataIndex : 'companyName'
					},
					{
						header : '联系人',
						dataIndex : 'contact'
					},
					{
						header : '电话号码',
						dataIndex : 'contactNumber'
					},
					{
						header : '手机号码',
						dataIndex : 'phoneNumber'
					},
					{
						header : 'E-mail',
						dataIndex : 'email'
					},
					{
						header : '注册时间',
						dataIndex : 'registerTime'
					},
					{
						header : '状态',
						dataIndex : 'status',
						renderer : function(v) {
							if (!v)
								return '待审核';
							if (v == 1) {
								return '待审核';
							} else if (v == 2) {
								return '审核通过';
							} else {
								return "审核不通过";
							}
						}
					},
					{
						header : '操作',
						width : 100,
						dataIndex : 'id',
						renderer : function(value, metaData, record, rowIndex,
								colIndex, store) {

							// 未审核或审核失败，允许修改
							return "<a href='#' onclick='clearUserPassword("
									+ value + ")'>清除密码</a>";
						}
					} ],
			sm : new Ext.grid.RowSelectionModel({
				singleSelect : false
			}),
			initComponent : function() {
				this.buildProxies();
				this.store = this.buildStore();
				// this.columns = this.buildColumns();
				this.bbar = this.buildBbar();
				this.tbar = this.buildTbar();
				crs.grid.ReviewedApplicantGridPanel.superclass.initComponent
						.call(this);

				this.store.load({
					params : {
						start : 0,
						limit : this.pageSize
					}
				}
				);
			},
			/* end of components appending to this panel */
			buildStore : function() {

				return new Ext.data.Store({
					proxy : this.defaultProxy,
					reader : new Ext.data.JsonReader({
						root : this.root,
						totalProperty : this.totalProperty,
						fields : this.fields
					})
				});

			},

			buildProxies : function() {

				this.defaultProxy = new Ext.data.HttpProxy({
					url : this.default_url,
					method : 'post'
				});

				this.searchProxy = new Ext.data.HttpProxy({
					url : this.search_url,
					method : 'post'
				});
			},
			buildBbar : function() {
				return new Ext.PagingToolbar({
					store : this.store,
					pageSize : this.pageSize,
					displayInfo : true,
					listeners : {
						'beforechange' : function(cmp) {
							this.clearStore();
							this.store.proxy = this.defaultProxy;
						},
						scope : this

					}
				});
			},
			buildTbar : function() {
				return new Ext.Toolbar({
					items : [
							'->',
							{
								xtype : 'textfield',
								id : 'companyNameSearch'
							},
							{
								xtype : 'button',
								text : '查询',
								handler : function(btn) {
									var searchValue = Ext.getCmp(
											"companyNameSearch").getValue();
									if (searchValue.trim().length == 0)
										return;
									this.clearStore();
									this.store.proxy = this.searchProxy;

									Ext.apply(this.store.baseParams, {
										"user.companyName" : searchValue
									});
									this.store.load({
										params : {
											start : 0,
											limit : this.pageSize
										}
									});
								}.createDelegate(this)

							}, '-' ]
				});
			},
			clearStore : function() {
				this.store.removeAll();
				this.store.baseParams = {};
				this.store.params = {};
			}

		/* end of handler implementation */
		});

Ext.reg("user_reviewed_grid", crs.grid.ReviewedApplicantGridPanel);